import { mapState, mapMutations } from 'vuex'
export default {
	name: 'headerMenu',
	data() {
		return {
			menuShow: false,
			index:0,
			menuList:[
				{name:"首页",path:"/"},
				{name:"日志",path:"/daily"},
				{name:"相册",path:"/album"},
				{name:"留言板",path:"/msgBoard"},
				{name:"聊天室",path:"/chatRoom"},
			],
		}
	},
	computed: {
		...mapState([
			'token'
		]),
	},
	methods: {
		...mapMutations([
			'TOKEN'
		]),
		//移動端菜單的顯示和隱藏
		menuOff() {
			this.menuShow = !this.menuShow;
		},
		
		to(path,i){
			this.$router.push({
				path: `${path}`
			});
			this.menuOff();
			this.index = i;
		},
		
		login() {
			this.index = null;
			this.$router.push({
				path: '/login'
			});
		}

	},
	created() {		
		this.$axios({
				method: 'get',
				url: '/user/isLogin?temp=' + Math.random(),
			})
			.then((res) => {
				if(res.data.status == "1") {
					console.log("已登录")
					this.TOKEN(true);
				} else {
					console.log("密码过期")
					this.TOKEN(false);
				}
			})
			.catch((error) => {
				alert("请求异常")
			})
	}
}